package com.ideal.frame.prefix.service;

import cn.hutool.core.collection.CollUtil;
import com.ideal.frame.jpa.JpaRepositoryImpl;
import com.ideal.frame.prefix.entity.PrefixSelfTb;
import com.ideal.frame.prefix.entity.QPrefixSelfTb;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * @author lad
 * @date 2021年9月12日20:26:05
 */
@Service
public class PrefixSelfTbService {

    @PersistenceContext
    protected EntityManager entityManager;
    private JpaRepositoryImpl<PrefixSelfTb, Long> repository;

    QPrefixSelfTb qPrefixSelfTb = QPrefixSelfTb.prefixSelfTb;

    @PostConstruct
    public void initRepo() {
        repository = new JpaRepositoryImpl<>(PrefixSelfTb.class, entityManager);
    }

    public PrefixSelfTb getCurrentPrefixSelf() {
        PrefixSelfTb prefixSelfTb = new PrefixSelfTb();
        List<PrefixSelfTb> list = repository.findAll();
        if (CollUtil.isNotEmpty(list)) {
            prefixSelfTb = list.get(0);
        }
        return prefixSelfTb;
    }
}
